package com.cl.short_video_java.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cl.short_video_java.mapper.VideoRoleMapper;
import com.cl.short_video_java.pojo.SysRoleMenu;
import com.cl.short_video_java.pojo.VideoRole;
import com.cl.short_video_java.service.SysRoleMenuService;
import com.cl.short_video_java.mapper.SysRoleMenuMapper;
import com.cl.short_video_java.service.VideoRoleService;
import com.cl.short_video_java.vo.role.RoleMenu;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author object
 * @description 针对表【sys_role_menu】的数据库操作Service实现
 * @createDate 2024-11-17 09:39:32
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
		implements SysRoleMenuService {

	private VideoRoleMapper videoRoleMapper;
	private SysRoleMenuMapper sysRoleMenuMapper;

	public SysRoleMenuServiceImpl(VideoRoleMapper videoRoleMapper,
								  SysRoleMenuMapper sysRoleMenuMapper) {
		this.videoRoleMapper = videoRoleMapper;
		this.sysRoleMenuMapper = sysRoleMenuMapper;
	}

	/**
	 * 保存修改的权限
	 *
	 * @param menuIds
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void save(RoleMenu menuIds) {
		long count = videoRoleMapper.selectCount(new QueryWrapper<VideoRole>().eq("role_id", menuIds.getRoleId()));
		Assert.isTrue(count == 1, "当前角色不存在");
		for (Integer menuId : menuIds.getMenuIds()) {
			SysRoleMenu sysRoleMenu = new SysRoleMenu();
			sysRoleMenu.setRoleId(Long.valueOf(menuId));
		}

	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void save(Integer id, List<Long> sysMenuList) {
		System.out.println(sysMenuList);
		this.update(new UpdateWrapper<SysRoleMenu>().eq("role_id", id).set("status", 0));
		for (Long sysMenuId : sysMenuList) {
			this.update(new UpdateWrapper<SysRoleMenu>().eq("menu_id", sysMenuId).set("status", 1));
		}
	}
}




